<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="Administrators"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="Administrators" type="Domain.Administrators" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="Administrators">
			<result property="id" column="id" dbType="Int"/>
			<result property="username" column="username" dbType="NVarChar"/>
			<result property="password" column="password" dbType="NVarChar"/>
			<result property="roles" column="roles" dbType="NVarChar"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[Administrators]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="Administrators">
			SELECT * 
			FROM [dbo].[Administrators]
		</select>
    <select id="login" parameterClass="hashtable" resultClass="Administrators" extends="FindAll">
      where username=#username# and password = #password#
    </select>
		<select id="GetModel" parameterClass="Administrators" resultClass="Administrators" extends="FindAll">
			WHERE
				([Administrators].[id] = #id,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="Administrators">
			INSERT INTO [dbo].[Administrators] (
				
				[username] , 
				[password] , 
				[roles]
			) VALUES (
				
				 #username,dbType=NVarChar# , 
				 #password,dbType=NVarChar# , 
				 #roles,dbType=NVarChar#
			)
		</insert>

		<update id="Update" parameterClass="Administrators">
			UPDATE [dbo].[Administrators] SET
				 [username] = #username,dbType=NVarChar#
				, [password] = #password,dbType=NVarChar#
				, [roles] = #roles,dbType=NVarChar#
			WHERE
				([id] = #id,dbType=Int#)
		</update>

		<delete id="Delete" parameterClass="Administrators">
			DELETE FROM [dbo].[Administrators]
			WHERE
				([id] = #id,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="Administrators">
			SELECT $columnNames$ FROM [dbo].[Administrators] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="Administrators">
      declare @indextable table(rno int identity(1,1),nid int)
      insert into @indextable(nid) select [id] from [dbo].[Administrators]
      where $condition$ order by $orderBy$

      select $columnNames$ from
      [dbo].[Administrators] ,@indextable t
      <![CDATA[
			where t.nid= [Administrators].id and t.rno>#startNo# and t.rno<=#endNo# 
      order by t.rno asc
			]]>
		</select>
		
	</statements>
</sqlMap>
